package com.briup.jz.web.controller;

import com.briup.jz.bean.AccountCustomer;
import com.briup.jz.bean.extend.AccountCustomerExtend;
import com.briup.jz.service.IAccountCustomerService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/accountcustomer")
@Api(description="顾客账户明细")
public class AccountCustomerController {
//    根据类型注入
    @Autowired
    private IAccountCustomerService iAccountCustomerService;
//    进行删除或者保存操作
@ApiOperation("新建顾客账户明细信息")
@ApiImplicitParams({
        @ApiImplicitParam(name = "transferMoney" ,value = "金额", paramType = "form"),
        @ApiImplicitParam(name = "description" ,value = "描述",paramType = "form"),
        @ApiImplicitParam(name = "type" ,value = "体现类型",paramType = "form",required = true),
        @ApiImplicitParam(name = "userId" ,value = "用户id",paramType = "form")
})
    @PostMapping("/save")
    public Message saveOrUpdate(AccountCustomer accountCustomer){
        iAccountCustomerService.saveOrUpdate(accountCustomer);
        return MessageUtil.success("操作成功");
    }
    //    删除操作
    @ApiOperation("删除顾客账户明细信息")
    @GetMapping("/delete")
    public Message delete(Long id){
        iAccountCustomerService.deleteById(id);
        return  MessageUtil.success("操作成功");
    }
    @ApiOperation("查询顾客账户明细信息")
    @GetMapping("/query")
    public Message query(Long id){
        List<AccountCustomer> accountCustomers = iAccountCustomerService.query(id);
        return MessageUtil.success(accountCustomers);
    }
    @ApiOperation("查询顾客账户明细信息")
    @GetMapping("/queryWithUser")
    public Message queryWithUser(Long id){
        List<AccountCustomerExtend> accountCustomerExtends = iAccountCustomerService.queryWithUser(id);
        return MessageUtil.success(accountCustomerExtends);
    }
}
